/*
 * @Description: file type
 * @Autor: HuiSir<www.zuifengyun.com>
 * @Date: 2022-06-27 10:57:24
 * @LastEditTime: 2022-07-07 11:24:55
 */
import { type IncomingHttpHeaders } from 'node:http'

export interface File {
    /**
     * File name (original, with extName)
     * 文件名（原始，带文件扩展名）
     */
    name: string

    /**
     * File extName, example `.exe`、`.xml`
     * 文件扩展名，如`.exe`、`.xml`
     */
    extName: string

    /**
     * File name (after reset, storage name)
     * 文件名（重设后，存储名称）
     */
    newName?: string

    /**
     * The size of the uploaded file in bytes. If the file is still being uploaded,
     * this property says how many bytes of the file have been written to disk yet.
     */
    size?: number

    /**
     * Keep 2 decimal places for file size with units, such as
     * `100.11 KB` and `100.12 MB`. Units are limited to KB, MB and GB.
     * 带单位的文件大小，保留2位小数，如`100.11 KB`、`100.12 MB`,单位只限KB、MB、GB
     */
    unitSize?: string

    /**
     * Absolute path (local storage), non-local storage can be empty.
     * 绝对路径（本地存储），非本地存储可为空
     */
    path?: string | null

    /**
     * Relative path, outer chain path.
     * 相对路径、外链路径
     * 便于数据库存储和前台访问(前端使用，因为path为绝对路径不安全)
     */
    src?: string

    /**
     * The mime type of this file, according to the uploading client.
     */
    type: string | null


    /**
     * A number representing the number of milliseconds between the Unix time epoch and when the file was last modified. 
     * Defaults to a value of Date.now().
     * 最后一次修改时间戳，毫秒数 (文件上传后需要修改文件名再存储，所以取Date.now()为最后修改时间)
     * @default `Date.now()`
     */
    lastModified: number

    /**
     * Unique ID of the file. (If it is a multipart upload mechanism, the unique ID of the file 
     * fragment is used. Uuid is used for assignment here).
     * 文件唯一标识，（若为分片上传机制，则为文件片段唯一标识，这里赋值使用uuid）。
     */
    chunkId: string
}

export interface Files {
    [file: string]: File | File[];
}

export interface IObj extends Object {
    [key: string]: any
}

export interface IData {
    /**
     * API链接参数
     */
    params?: IObj
    /**
     * GET Query 参数
     */
    query?: IObj
    /**
     * json、text/*、application/x-www-form-urlencoded
     */
    body?: IObj
    /**
     * multipart/form-data，不含file
     */
    raw?: IObj
    /**
     * multipart/form-data 中的文件
     */
    files?: Files

    /**
     * header
     */
    header?: IncomingHttpHeaders

    /**
     * ctx.ip
     */
    ip?: string

    /**
     * ctx.host
     */
    host?: string

    /**
     * cookie
     */
    cookie?: IObj

    /**
     * Request method
     */
    method: string
}